package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocBondsmanDao;
import com.irdstudio.cdp.pboc.service.domain.PbocBondsman;
import com.irdstudio.cdp.pboc.service.facade.PbocBondsmanService;
import com.irdstudio.cdp.pboc.service.vo.PbocBondsmanVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 对外担保信息汇总				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocBondsmanService")
public class PbocBondsmanServiceImpl implements PbocBondsmanService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocBondsmanServiceImpl.class);

	@Autowired
	private PbocBondsmanDao pbocBondsmanDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocBondsman(PbocBondsmanVO inPbocBondsmanVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocBondsmanVo.toString());
		int num = 0;
		try {
			PbocBondsman pbocBondsman = new PbocBondsman();
			beanCopy(inPbocBondsmanVo, pbocBondsman);
			num = pbocBondsmanDao.insertPbocBondsman(pbocBondsman);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocBondsmanVO inPbocBondsmanVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocBondsmanVo);
		int num = 0;
		try {
			PbocBondsman pbocBondsman = new PbocBondsman();
			beanCopy(inPbocBondsmanVo, pbocBondsman);
			num = pbocBondsmanDao.deleteByPk(pbocBondsman);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocBondsmanVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocBondsmanVO inPbocBondsmanVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocBondsmanVo.toString());
		int num = 0;
		try {
			PbocBondsman pbocBondsman = new PbocBondsman();
			beanCopy(inPbocBondsmanVo, pbocBondsman);
			num = pbocBondsmanDao.updateByPk(pbocBondsman);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocBondsmanVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocBondsmanVO queryByPk(PbocBondsmanVO inPbocBondsmanVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocBondsmanVo);
		try {
			PbocBondsman queryPbocBondsman = new PbocBondsman();
			beanCopy(inPbocBondsmanVo, queryPbocBondsman);
			PbocBondsman queryRslPbocBondsman = pbocBondsmanDao.queryByPk(queryPbocBondsman);
			if (Objects.nonNull(queryRslPbocBondsman)) {
				PbocBondsmanVO outPbocBondsmanVo = beanCopy(queryRslPbocBondsman, new PbocBondsmanVO());
				logger.debug("当前查询结果为:"+ outPbocBondsmanVo.toString());
				return outPbocBondsmanVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocBondsmanVO> queryAllOwner(PbocBondsmanVO pbocBondsmanVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocBondsmanVO> list = null;
		try {
			List<PbocBondsman> pbocBondsmans = pbocBondsmanDao.queryAllOwnerByPage(pbocBondsmanVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocBondsmans.size());
			pageSet(pbocBondsmans, pbocBondsmanVo);
			list = (List<PbocBondsmanVO>) beansCopy(pbocBondsmans, PbocBondsmanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocBondsmanVO> queryAllCurrOrg(PbocBondsmanVO pbocBondsmanVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocBondsman> pbocBondsmans = pbocBondsmanDao.queryAllCurrOrgByPage(pbocBondsmanVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocBondsmans.size());
		List<PbocBondsmanVO> list = null;
		try {
			pageSet(pbocBondsmans, pbocBondsmanVo);
			list = (List<PbocBondsmanVO>) beansCopy(pbocBondsmans, PbocBondsmanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocBondsmanVO> queryAllCurrDownOrg(PbocBondsmanVO pbocBondsmanVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocBondsman> pbocBondsmans = pbocBondsmanDao.queryAllCurrDownOrgByPage(pbocBondsmanVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocBondsmans.size());
		List<PbocBondsmanVO> list = null;
		try {
			pageSet(pbocBondsmans, pbocBondsmanVo);
			list = (List<PbocBondsmanVO>) beansCopy(pbocBondsmans, PbocBondsmanVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
